import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:ladder_cash/app/app.dart';
import 'package:ladder_cash/app/com/http/http_request.dart';
import 'package:ladder_cash/app/com/http/Res.dart';
import 'package:ladder_cash/app/com/service/burial_point_service.dart';
import 'package:ladder_cash/app/com/view/flutter_pickers_master/time_picker/model/date_mode.dart';
import 'package:ladder_cash/app/com/view/flutter_pickers_master/time_picker/model/pduration.dart';
import 'package:ladder_cash/app/com/view/my_app_bar.dart';
import 'package:ladder_cash/app/com/view/my_date_picker.dart';
import 'package:ladder_cash/app/key_mix.dart';
import 'package:ladder_cash/generated/l10n.dart';
import 'package:ladder_cash/value/app_colors.dart';
import 'package:ladder_cash/value/app_const.dart';
import 'package:ladder_cash/value/app_lstyle.dart';
import 'package:liuxlcommon/lget/LView.dart';
import 'package:liuxlcommon/lget/lget.dart';
import 'package:liuxlcommon/util/string_utils.dart';
import 'package:liuxlcommon/view/lxl_widget.dart';
import 'package:liuxlcommon/view/my_style.dart';

class IdFrontConfirmEditPage extends LView<IdFrontConfirmEditLogic> {
  IdFrontConfirmEditLogic logic = Get.put(IdFrontConfirmEditLogic());
  var data;
  var title;

  IdFrontConfirmEditPage(this.title, this.data);

  @override
  get init {
    data['name'.hx] = data['confirmList'.hx][0]['valueStr'.hx];
    data['id_card_number'.hx] = data['confirmList'.hx][1]['valueStr'.hx];
    data['birthday'.hx] = data['confirmList'.hx][2]['valueStr'.hx];
  }

  @override
  get body => GestureDetector(
      onTap: () {
        OldLInput.unfocus();
      },
      child: Scaffold(
          appBar: MyAppBar("Authentication"),
          body: LColumn.eazy([
            LText.easy(
                    data['confirmStr'.hx], 12.sp, fw6, const Color(0xFFF14857))
                .css(
                    'width:375px;height:62px;background:#FFEDEC;padding:16px; '),
            12.lsh,
            LColumn.eazy([
              31.lsh,
              20.lsh,
              itemInput(
                  data['confirmList'.hx][0]['titleStr'.hx],
                  data['confirmList'.hx][0]['titleStr'.hx],
                  data['name'.hx],
                  (txt) => data['name'.hx] = txt),
              itemInput(
                  data['confirmList'.hx][1]['titleStr'.hx],
                  data['confirmList'.hx][1]['titleStr'.hx],
                  data['id_card_number'.hx],
                  (txt) => data['id_card_number'.hx] = txt),
              itemDate(data['confirmList'.hx][2]['titleStr'.hx], '',
                  data['birthday'.hx]),
              LExpand(),
              LText('Confrm And Submit').style(rzBtnSty).onTapL(() async {
                BurialPointService.end(BPoint.idFront);
                Res r = await HttpRequest().postRes(
                    '/v3/certify/save-base-info'.hx,
                    <String, dynamic>{
                      'product_id'.hx: data['product_id'],
                      data['confirmList'.hx][0]['code'.hx]: data['name'.hx],
                      data['confirmList'.hx][1]['code'.hx]:
                          data['id_card_number'.hx],
                      data['confirmList'.hx][2]['code'.hx]: data['birthday'.hx],
                      "type":   11,
                    },
                    loadingText: S.current.loading);
                if (r.success) {
                  Get.back(result: true);
                }
              }),
              LSizeH(LGet.bottomPadding(logic.context) + 10.w)
            ]).flex(1)
          ])));

  itemInput(title, hint, value, onChange(text)) => LColumn.eazy([
        LRow.eazy([
          LContainer()
              .bgColor(AppColors.primaryColor)
              .radius(3.5.w)
              .size(7.w, 15.w),
          13.lsw,
          LText.easy(title, 15.sp, fw5, const Color(0xFF333333)).flex(1),
        ]).padding(left: 14.w).size(null, 39.w),
        LInput(value,
            lStyle:
                LStyle(alignment: Alignment.centerLeft, css: '''width: 307px;
            padding-left:34px;
height: 53px; background: #F6F8F9;
border-radius: 99px 99px 99px 99px;'''),
            lInputType: LInputType.TEXT, onChanged: (txt) {
          onChange(txt);
        })
      ]).size(307.w, null);

  itemDate(title, hint, value) => LColumn.eazy([
        LRow.eazy([
          LContainer()
              .bgColor(AppColors.primaryColor)
              .radius(3.5.w)
              .size(7.w, 15.w),
          13.lsw,
          LText.easy(title, 15.sp, fw5, const Color(0xFF333333)).flex(1),
        ]).padding(left: 14.w).size(null, 39.w),
        LText(
          StringUtils.defaultValue(data['birthday'.hx], S.current.dateBirth),
          lStyle: LStyle(alignment: Alignment.centerLeft, css: '''width: 307px;
            padding-left:34px;
height: 53px; background: #F6F8F9;
border-radius: 99px 99px 99px 99px;''')
            ..color = StringUtils.isEmpty(data['birthday'.hx])
                ? AppColors.textSecondColor
                : AppColors.textColor
            ..hintText = S.current.birthdateTitle,
          onTap: () {
            MyDatePicker().showDatePicker(logic.context,
                selectTxt: data['birthday'.hx] ?? (data['birthday'.hx] ?? ""),
                onConfirm: (txt, PDuration p) {
              data['birthday'.hx] = txt;
              logic.update();
            }, model: DateMode.YMD);
          },
        )
      ]).size(307.w, null);
}

class IdFrontConfirmEditLogic extends LViewLogic {}
